﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharaAnimationMonster : MonoBehaviour
{
    private GridMove m_grid_move;
    private Animator m_animator;
    private bool m_dead;
    // Start is called before the first frame update
    void Start()
    {
        m_dead = false;
        m_grid_move = GetComponent<GridMove>();
        m_animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (!m_dead)
        {
            Quaternion quaternion = Quaternion.LookRotation(m_grid_move.GetDirection());
            float t = 1.0f - Mathf.Pow(0.75f, Time.deltaTime * 30.0f);
            transform.localRotation = Quaternion.Lerp(transform.localRotation, quaternion, t);
        }

    }

    public void OnDead()
    {
        if (m_dead == false)
        {
            m_animator.SetTrigger("begin_dead");
            Destroy(this.transform.gameObject, 1);
        }
        m_dead = true;

    }

    public void Normal()
    {
        m_animator.Play("idle");
    }
}
